#!/bin/bash
set -e

while getopts  ":s:w:c:p:g:d" opts
do
	case  $opts  in
	s)
		sample_name=$OPTARG
		;;
	w)
		window=$OPTARG
		;;
	c)
		c_const=$OPTARG
		;;
	g)
        ref_genome=$OPTARG
        ;;
	p)
        out_prefix=$OPTARG
        ;;
	\?)
		echo `basename $0` "[-s sample_name] [-w window_size] [-g ref_genome_file] <r1.fq> <r2.fq>"
		exit 1
		;;
	esac
done
shift $(($OPTIND - 1))

if [ -z "$2" ]; then
	echo `basename $0` '[-s sample_name] [-w window_size] [-g ref_genome_file] <r1.fq> <r2.fq>'
	exit 1
fi

makedir=true
#-----------------------------------------------
#-----------------------------------------------
. /mnt/ilustre/app/medical/tools/.var #---------
#-----------------------------------------------
#-----------------------------------------------
# log=.log
# if [ ! -e "$log" ]; then
	# :> $log
# fi

if [ -z $out_prefix ]; then
	out_prefix=1
fi

if [ -z "$window" ]; then
	window=200000
fi


# if [ -z "$ref_genome" ]; then
	# ref_genome=ref_genome
# fi


if
echo $1 |perl -n -e 'if(/^\//){exit 0;}else{exit 2;}' 2>>$log
then
cutadp.sh $1 $2
else
cutadp.sh ../$1 ../$2
fi

align2bam.sh -s $sample_name 1.1.cut.fastq 1.2.cut.fastq

hmmcopy0727.sh -w $window 1.sort.bam $data_path/cnv_ref/2.sort.bam

summ_sc_gatk.sh 1.sort.bam $data_path/intervals/1/cnv_sc/b37.rand.site.bed

